package com.txf.simple.utils;

import com.txf.simple.app.MyApp;
import com.txf.simple.tools.EquipmentTools;
import com.txf.simple.tools.Logger;

/**
 * UI工具类
 * */
public class UIUtils {
    /**
     * 获取导航栏高度
     * @return
     */
    public static int getDaoHangHeight() {
        int i = MyApp.getContextInstance().getResources().getIdentifier("config_showNavigationBar", "bool", "android");
        int j = 0;
        if (i != 0) {
            int k = MyApp.getContextInstance().getResources().getIdentifier("navigation_bar_height", "dimen", "android");
            Logger.i("导航栏高度：" + MyApp.getContextInstance().getResources().getDimensionPixelSize(k));
            j = MyApp.getContextInstance().getResources().getDimensionPixelSize(k);
        }
        return j;
    }
    /**
     * 获取状态栏高度
     * @return
     */
    public static int getStatusBarHeight() {
        int i = MyApp.getContextInstance().getResources().getIdentifier("status_bar_height", "dimen", "android");
        int j = 0;
        if (i > 0)
            j = MyApp.getContextInstance().getResources().getDimensionPixelSize(i);
        Logger.i("状态栏高度：" + j);
        return j;
    }
    /**
     * px转dp
     * @return
     * */
    public static int px2dp(float paramFloat) {
        return (int) (0.5F + paramFloat / EquipmentTools.getInstance().getSCREEN_DENSITY());
    }
    /**
     * dp转px
     * @return
     * */
    public static int dp2px(float paramFloat) {
        return (int) (0.5F + paramFloat * EquipmentTools.getInstance().getSCREEN_DENSITY());
    }

    /**
     * 将px转sp
     * @return
     */
    public static int px2sp(float pxValue) {
        return (int) (pxValue / EquipmentTools.getInstance().getSCALED_DENSITY() + 0.5f);
    }

    /**
     * 将sp转px
     * @return
     */
    public static int sp2px(float spValue) {
        return (int) (spValue * EquipmentTools.getInstance().getSCALED_DENSITY() + 0.5f);
    }
}